package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonFillBlankBean;
import com.fancy.learncenter.common.JumpIntentKey;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;

import java.util.List;

/**
 * Created by shiweiwei on 2018/1/31.
 */

public class CustomTagAdapter extends TagAdapter<CartoonFillBlankBean> {
    JumpIntentKey.QUESTION_ENTER_TYPE type;
    Context mContext;

    public CustomTagAdapter(Context mContext, List<CartoonFillBlankBean> datas, JumpIntentKey.QUESTION_ENTER_TYPE type) {
        super(datas);
        this.type = type;
        this.mContext = mContext;
    }

    @Override
    public View getView(FlowLayout parent, int position, CartoonFillBlankBean item) {
        RelativeLayout view = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.question_name_item_layout, parent, false);
        final TextView question = (TextView) view.findViewById(R.id.question_letter);


        if ("##".equals(item.getValue())) {
            switch (item.getStatus()) {
                case STATUS_DEFAULT:
                    question.setText("");
                    view.setBackgroundResource(R.mipmap.cartoon_transparent_word);
                    break;
                case STATUS_CHOOSE:
                    if (!TextUtils.isEmpty(item.getOptionValue())) {
                        question.setText(item.getOptionValue());
                        question.setGravity(Gravity.CENTER);
                    } else {
                        question.setText("");
                    }
                    view.setBackgroundResource(R.mipmap.cartoon_white_dot);
                    break;
                case STATUS_WORD:
                    if (!TextUtils.isEmpty(item.getOptionValue())) {
                        question.setText(item.getOptionValue());
                    }
                    view.setBackgroundResource(R.mipmap.cartoon_white_dot);
                    break;

                case STATUS_WRONG:
                    if (!TextUtils.isEmpty(item.getOptionValue())) {
                        question.setText(item.getOptionValue());
                    }
                    view.setBackgroundResource(R.mipmap.cartoon_word_error);
                    break;

                case STATUS_RIGHT:
                    if (!TextUtils.isEmpty(item.getOptionValue())) {
                        question.setText(item.getOptionValue());
                    }
                    switch (type) {
                        case TEACHER_WORK_PREVIEW:
                            view.setBackgroundResource(R.drawable.teacher_work_preivew_spell_word_right);
                            break;
                        default:
                            view.setBackgroundResource(R.mipmap.cartoon_word_right);
                            break;
                    }

                    break;

            }

        } else {
            question.setText(item.getValue());
            question.setBackground(null);
        }


        return view;
    }
}
